#include "lock.hpp"

using namespace vpm::utils;

Lock::Lock(Lockable & lockable, LockType lockType): myLockable(lockable)
{
	switch ( lockType )
	{
	case READLOCK:
		{
			myLockable.lock_read();
			break;
		}

	case WRITELOCK:
		{
			myLockable.lock_write();
			break;
		}

	default:
		{
			myLockable.lock();
			break;
		}
	}
}

Lock::~Lock()
{
	myLockable.unlock();
}

ReadLock::ReadLock(Lockable & lockable): Lock(lockable, READLOCK)
{
}

WriteLock::WriteLock(Lockable & lockable): Lock(lockable, WRITELOCK)
{
}

